package cn.edu.scau.dropship.mapper;

import cn.edu.scau.dropship.entity.Order;
import cn.edu.scau.dropship.entity.OrderExample;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Arg;
import org.apache.ibatis.annotations.ConstructorArgs;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderMapper {
    @SelectProvider(type=OrderSqlProvider.class, method="countByExample")
    long countByExample(OrderExample example);

    @DeleteProvider(type=OrderSqlProvider.class, method="deleteByExample")
    int deleteByExample(OrderExample example);

    @Delete({
        "delete from orders",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into orders (id, create_time, ",
        "total_money, send_time, ",
        "state, send_No, mvo_id, ",
        "bvo_id, address_id)",
        "values (#{id,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{totalMoney,jdbcType=DOUBLE}, #{sendTime,jdbcType=TIMESTAMP}, ",
        "#{state,jdbcType=VARCHAR}, #{sendNo,jdbcType=INTEGER}, #{mvoId,jdbcType=INTEGER}, ",
        "#{bvoId,jdbcType=INTEGER}, #{addressId,jdbcType=INTEGER})"
    })
    int insert(Order record);

    @InsertProvider(type=OrderSqlProvider.class, method="insertSelective")
    int insertSelective(Order record);

    @SelectProvider(type=OrderSqlProvider.class, method="selectByExample")
    @ConstructorArgs({
        @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
        @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
        @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
        @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectByExample(OrderExample example);

    @Select({
        "select",
        "id, create_time, total_money, send_time, state, send_No, mvo_id, bvo_id, address_id",
        "from orders",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ConstructorArgs({
        @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
        @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
        @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
        @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
        @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
        @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
        @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    Order selectByPrimaryKey(Integer id);

    @UpdateProvider(type=OrderSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") Order record, @Param("example") OrderExample example);

    @UpdateProvider(type=OrderSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") Order record, @Param("example") OrderExample example);

    @UpdateProvider(type=OrderSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Order record);

    @Update({
        "update orders",
        "set create_time = #{createTime,jdbcType=TIMESTAMP},",
          "total_money = #{totalMoney,jdbcType=DOUBLE},",
          "send_time = #{sendTime,jdbcType=TIMESTAMP},",
          "state = #{state,jdbcType=VARCHAR},",
          "send_No = #{sendNo,jdbcType=INTEGER},",
          "mvo_id = #{mvoId,jdbcType=INTEGER},",
          "bvo_id = #{bvoId,jdbcType=INTEGER},",
          "address_id = #{addressId,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Order record);






    @Select({
            "select `orders`.* from `orders` where mvo_id = #{mvo_id} and state = 'A'"
    })
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectToBePaidFromOrder(Integer mvo_id);


    @Select({
            "select `orders`.* from `orders` where mvo_id = #{id} and state = 'B'"
    })
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectToBeDeliveredFromOrder(Integer mvo_id);


    @Select({
            "select `orders`.* from `orders` where mvo_id = #{id} and state = 'C'"
    })
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectDeliveredFromOrder(Integer mvo_id);



    @Select({
            "select `orders`.* from `orders` where mvo_id = #{id} and state = 'D'"
    })
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectFinishedFromOrder(Integer mvo_id);




    @Select({
            "select `orders`.* from `orders` where mvo_id = #{id} and state = 'E'"
    })
    @ConstructorArgs({
            @Arg(column="id", javaType=Integer.class, jdbcType=JdbcType.INTEGER, id=true),
            @Arg(column="create_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="total_money", javaType=Double.class, jdbcType=JdbcType.DOUBLE),
            @Arg(column="send_time", javaType=Date.class, jdbcType=JdbcType.TIMESTAMP),
            @Arg(column="state", javaType=String.class, jdbcType=JdbcType.VARCHAR),
            @Arg(column="send_No", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="mvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="bvo_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER),
            @Arg(column="address_id", javaType=Integer.class, jdbcType=JdbcType.INTEGER)
    })
    List<Order> selectCanceledFromOrder(Integer mvo_id);


    @Update({
            "update `orders` set state = #{state} where id = #{id}"
    })
    int updateOrderState(@Param("id")Integer id  , @Param("state")String state);
}